package com.heima.mapper;

import com.github.pagehelper.Page;
import com.heima.dto.CourseDto;
import com.heima.pojo.Course;
import com.heima.vo.CourseVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface CourseMapper{
    /**
     * 分页查询课程列表
     * @param courseDto
     * @return
     */
    Page<CourseVo> pageQueryCourse(CourseDto courseDto);

    /**
     * 查询下拉课程列表
     * @param
     * @return
     */
    //@Select("select name from tb_course")
    List<Course> listselect();

    /**
     * 添加课程
     * @param course
     */
    @Update("insert into tb_course(name,subject,create_time,price,applicable_person,info) " +
            "values(#{name},#{subject},#{createTime},#{price},#{applicablePerson},#{info})")
    void addCourse(Course course);

    /**
     * 根据id查询课程
     * @param id
     * @return
     */
    @Select("select * from tb_course where id = #{id}")
    CourseVo getById(Integer id);

    /**
     * 修改课程
     * @param course
     */
    @Update("update tb_course set name = #{name},subject = #{subject},price = #{price},applicable_person = #{applicablePerson},info = #{info} where id = #{id}")
    void updateCourse(Course course);

    //查询签约该课程的合同数量
    @Select("select count(*) from tb_contract where course_id = #{id}")
    int selectCountById(Integer id);

    /**
     * 删除课程
     * @param id
     */
    @Delete("delete from tb_course where id = #{id}")
    void deleteById(Integer id);
}
